﻿Imports MySql.Data.MySqlClient
Public Class frmsearch_addcontainer
    Dim mysql As MySqlConnection = main_form.mysqlconection
    Dim mySqlCommand As New MySqlCommand
    Dim mySqlAdaptor As New MySqlDataAdapter
    Dim mySqlReader As MySqlDataReader
    Public Shared idvoyage As Integer
    Public Shared datepenang As String
    Public Shared datethai As String
    Public Shared timehhmm As String
    Public Shared datetime As String
    Public Shared sumint As Double

    Dim textDate As String
    Dim stringDate() As String
    Dim stringhour() As String
    Dim sumtxt As String
    Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click

        If ListView1.SelectedItems.Count > 0 Then
            Dim cf As New frmadd_container

            cf.MdiParent = Me.MdiParent
            Me.Close()
            cf.Dock = DockStyle.Fill
            cf.Show()
        Else
            MsgBox("กรุณาเลือกข้อมูล")
        End If

    End Sub

    Private Sub frmsearch_addcontainer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If

        mySqlCommand.CommandText = "Select * from voyage order by VOYAGEID DESC  LIMIT 25  ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())

                With ListView1.Items.Add(Format(mySqlReader("VOYAGEID"), "000"))

                    .SubItems.Add("N")
                    .SubItems.Add(mySqlReader("VOYVESNAMEN"))

                    .SubItems.Add(mySqlReader("VOYDATESN"))
                    .SubItems.Add(mySqlReader("VOYDATEEN"))
                    .SubItems.Add(mySqlReader("VOYTIMEHHMMNN"))
                End With




            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub

    Private Sub ButtonItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonItem1.Click

        searchdata()

    End Sub
    Public Sub searchdata()
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        mySqlCommand.CommandText = "Select * from voyage where VOYAGEID like '%" & TextBoxItem2.Text & "%' order by VOYAGEID DESC  LIMIT 25;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                ListView1.Items.Clear()
                With ListView1.Items.Add(Format(mySqlReader("VOYAGEID"), "000"))

                    .SubItems.Add("N")
                    .SubItems.Add(mySqlReader("VOYVESNAMEN"))

                    .SubItems.Add(mySqlReader("VOYDATESN"))
                    .SubItems.Add(mySqlReader("VOYDATEEN"))
                    .SubItems.Add(mySqlReader("VOYTIMEHHMMNN"))

                End With




            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub

    Private Sub TextBoxItem2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBoxItem2.KeyDown
        If e.KeyCode = Keys.Enter Then
            searchdata()
        End If
    End Sub

    Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click

        idvoyage = ListView1.SelectedItems(0).SubItems(0).Text
        timehhmm = ListView1.SelectedItems(0).SubItems(4).Text
        datetime = ListView1.SelectedItems(0).SubItems(5).Text

        stringDate = Split(timehhmm, "-")
        'MsgBox(stringDate(0) + stringDate(1) + stringDate(2))
        stringhour = Split(datetime, ":")
        'MsgBox(stringhour(0) + stringhour(1))
        sumtxt = stringDate(2) + stringDate(1) + stringDate(0) + stringhour(0) + stringhour(1)

        sumint = CDbl(sumtxt) + 100

        datethai = sumtxt + "00"
        datepenang = sumint.ToString + "00"

    End Sub
End Class